package com.moon.game.manager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.moon.game.exception.GException;
import com.moon.game.resource.model.Gift;

/**
 * @description 礼包管理
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-8-7 下午2:27:50
 */
public class GiftMG {
	private static final Logger log = Logger.getLogger(GiftMG.class);
	public static GiftMG instance = new GiftMG();
	/**礼包资源*/
	private static Map<Integer, Gift> giftMap = new HashMap<Integer, Gift>();
	public static final Gift getGiftById(int giftId) {
		return giftMap.get(giftId);
	}
	public static final Map<Integer, Gift> getGiftMap() {
		return giftMap;
	}
	private GiftMG() {}
	public void init() throws GException{
		if (instance == null) {
			instance = new GiftMG();
		}
		log.debug("load gift end...");
		try {
			loadAllGift();
		} catch (Exception e) {
			throw new GException("load gift err...");
		}
		log.debug("load gift end...");
	}
	
	private void loadAllGift() {
		List<Gift> gifts = DBManager.queryGiftConfig();
		if (gifts != null) {
			for (Gift gift : gifts) {
				giftMap.put(gift.getId(), gift);
			}
		}
	}
}
